package com.scheduler.backend.controller;

import com.scheduler.backend.bl.PeopleService;
import com.scheduler.backend.vo.ResponseVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@RestController()
@CrossOrigin
public class PeopleController {

    @Autowired
    private PeopleService peopleService;

    @RequestMapping(value = "/getStaffGanttByDate/{date}", method = RequestMethod.GET)
    @Operation(summary = "根据Date获取员工甘特图", description = "根据Date获取员工甘特图", method = "GET")
    @Parameter(name = "date", description = "日期", required = true)
    public ResponseVO getStaffGanttByDate(@PathVariable("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                                          HttpServletResponse response) {
        if (response != null) {
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Cache-Control", "no-cache");
        }
        return peopleService.getStaffGanttByDate(date);
    }

    //按hour的暂时放着
    @RequestMapping(value = "/getStaffLoadRatioByDateInHour/{date}", method = RequestMethod.GET)
    @Operation(summary = "根据Date获取员工负载率/小时", description = "根据Date获取员工负载率/小时", method = "GET")
    @Parameter(name = "date", description = "日期", required = true)
    public ResponseVO getStaffLoadRatioByDateInHour(@PathVariable("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                                                    HttpServletResponse response) {
        if (response != null) {
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Cache-Control", "no-cache");
        }
        return peopleService.getStaffLoadRatioByDateInHour(date);
    }

    @RequestMapping(value = "/getStaffLoadRatioByDateInDay/{date}", method = RequestMethod.GET)
    @Operation(summary = "根据Date获取员工负载率/天", description = "根据Date获取员工负载率/天", method = "GET")
    @Parameter(name = "date", description = "日期", required = true)
    public ResponseVO getStaffLoadRatioByDateInDay(@PathVariable("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                                                   HttpServletResponse response) {
        if (response != null) {
            response.setHeader("Access-Control-Allow-Origin", "*");
            response.setHeader("Cache-Control", "no-cache");
        }
        return peopleService.getStaffLoadRatioByDateInDay(date);
    }
}
